<template>
  <div class="page-content padding-top">
    <list class="von-checkbox">
      <item style="padding: 10px 15px;border:1 px solid #666">
        <input type="text" style="height:44px;" v-model="search" placeholder="输入店铺名称快速查找">
      </item>
      <item class="item-icon-right" v-for="(item,index) in arrto" @click.native="selectItem(item.shopName,index)">
        {{item.shopName}}<i :class="{'icon ion-ios-checkmark-empty assertive':ind == index}"></i>
      </item>
    </list>
  </div>
</template>
<script>
import { bus } from 'bus.js'
  export default {
    data() {
      return {
        arr:[],
        name:[],
        value:[],
        ind:null,
        arrto: [],
        search: ''
      }
    },
    created(){
      var _this = this;
      axios.get(baseUrl+'/controller/getShopList',{params:{
          marketId:sess.get('userSession').marketId,
          shopState:1
        }
      })
      .then(function(res){
        _this.arr = res.data.result;
        for (var i = 0; i < _this.arr.length; i++) {
          _this.name.push(_this.arr[i].shopName);
          _this.value.push(_this.arr[i].shopId);
        }
        _this.arrto = _this.arr
      })
    },
    methods: {
      selectItem(a,i){
        this.ind = i;
        bus.$emit('shopId', this.value[i]);
        bus.$emit('shopName', a);
      }
    },
    watch:{
      'search' () {
        console.log(this.search.length)
        if (this.search.length == 0) {
          this.arrto = this.arr
        } else {
          console.log(this.arr)
          this.arrto = this.arr.filter(item => item.shopName.indexOf(this.search) != -1)
          
        }
      }
    }
  }
</script>

